<html>
<head><meta charset="utf-8"><title>upvar access spans · t-compiler/wg-rfc-2229 · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/index.html">t-compiler/wg-rfc-2229</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html">upvar access spans</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="201182297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201182297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201182297">(Jun 17 2020 at 18:31)</a>:</h4>
<p>Looks like <a href="https://github.com/rust-lang/project-rfc-2229/issues/6">#6</a> will be blocked until we get <code>closure_captures</code> to use <code>PlaceUnique</code>. </p>
<p>This is because the <code>span</code> stored within <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/struct.Upvar.html">Upvar</a> points to the expression   for the access where as the <code>hir_id</code> in closure_captures (both key and within the value) store hir_id to the variable. <a href="https://github.com/rust-lang/rust/pull/72591/files#diff-193820a23727493def60049c0b6af47eL119">creating closure_catures</a>.</p>
<p>With recent changes made to track unused variables in closures, certain tests are failing because we have the wrong span (<code>tcx.hir().span(var_hir_id)</code>) and therefore we indicate the wrong error line.</p>
<p>Eg: <a href="https://github.com/rust-lang/rust/pull/72465/files#diff-acaa1896213b8b463386a5f83cb038c3">https://github.com/rust-lang/rust/pull/72465/files#diff-acaa1896213b8b463386a5f83cb038c3</a></p>
<p><a href="/user_uploads/4715/TAaWJ2tL6ENe4eQ84LOqjR5P/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/TAaWJ2tL6ENe4eQ84LOqjR5P/image.png" title="image.png"><img src="/user_uploads/4715/TAaWJ2tL6ENe4eQ84LOqjR5P/image.png"></a></div>



<a name="201182572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201182572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201182572">(Jun 17 2020 at 18:33)</a>:</h4>
<p><code>PlaceUnique</code> would contain the hir_id of the expression so we can use that to get the correct span</p>



<a name="201184736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201184736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201184736">(Jun 17 2020 at 18:51)</a>:</h4>
<p><span class="user-mention" data-user-id="281950">@Aman Arora</span> hmm</p>



<a name="201184750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201184750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201184750">(Jun 17 2020 at 18:51)</a>:</h4>
<p>I'm not sure I understand yet</p>



<a name="201184800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201184800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201184800">(Jun 17 2020 at 18:51)</a>:</h4>
<p>ok ok I see</p>



<a name="201184802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201184802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201184802">(Jun 17 2020 at 18:51)</a>:</h4>
<p>so</p>



<a name="201184819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201184819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201184819">(Jun 17 2020 at 18:51)</a>:</h4>
<p>you should be able to get the definition span</p>



<a name="201185084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185084">(Jun 17 2020 at 18:53)</a>:</h4>
<p>No we would be about to get the expression span, so <code>foo.x</code>  instead of <code> let foo = ...</code></p>



<a name="201185119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185119">(Jun 17 2020 at 18:53)</a>:</h4>
<p>sorry, I got interrupted</p>



<a name="201185218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185218">(Jun 17 2020 at 18:54)</a>:</h4>
<p>so, if you have the <code>hir_id</code> of the acess to <code>foo</code>.. you <em>can</em> get to the declaration span</p>



<a name="201185237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185237">(Jun 17 2020 at 18:54)</a>:</h4>
<p>but it might be kind of annoying</p>



<a name="201185251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185251">(Jun 17 2020 at 18:54)</a>:</h4>
<p>there is some table or other that stores "what is the hir-id of the variable this was resolved to by name resolution"</p>



<a name="201185289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185289">(Jun 17 2020 at 18:55)</a>:</h4>
<p>that said</p>



<a name="201185301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185301">(Jun 17 2020 at 18:55)</a>:</h4>
<p>I guess I'm confused</p>



<a name="201185313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185313">(Jun 17 2020 at 18:55)</a>:</h4>
<p>don't you have the upvar id or something?</p>



<a name="201185355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185355">(Jun 17 2020 at 18:55)</a>:</h4>
<p>er, wait, is the problem that you are <em>now</em> getting the declaration span</p>



<a name="201185357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185357">(Jun 17 2020 at 18:55)</a>:</h4>
<p>and you <em>want</em> the access span?</p>



<a name="201185359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185359">(Jun 17 2020 at 18:55)</a>:</h4>
<p>maybe I had this backwards</p>



<a name="201185371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185371">(Jun 17 2020 at 18:55)</a>:</h4>
<p>I guess that's what your diff suggests</p>



<a name="201185620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185620">(Jun 17 2020 at 18:57)</a>:</h4>
<p>Yes we want the access span for expression within the closure</p>



<a name="201185779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185779">(Jun 17 2020 at 18:59)</a>:</h4>
<p>ok ok</p>



<a name="201185791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185791">(Jun 17 2020 at 18:59)</a>:</h4>
<p>ok so</p>



<a name="201185794"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185794" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185794">(Jun 17 2020 at 18:59)</a>:</h4>
<p>I see</p>



<a name="201185797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185797">(Jun 17 2020 at 18:59)</a>:</h4>
<p>so you are saying that</p>



<a name="201185811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185811">(Jun 17 2020 at 18:59)</a>:</h4>
<p>using <code>upvars_mentioned</code> was getting you the <em>access</em> span</p>



<a name="201185824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185824">(Jun 17 2020 at 18:59)</a>:</h4>
<p>but using <code>closure_captures</code> is getting you the definition span?</p>



<a name="201185832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185832">(Jun 17 2020 at 18:59)</a>:</h4>
<p>you <em>can</em> get an access span</p>



<a name="201185995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201185995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201185995">(Jun 17 2020 at 19:00)</a>:</h4>
<p>well I wonder if the way we do it now</p>



<a name="201186016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201186016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201186016">(Jun 17 2020 at 19:00)</a>:</h4>
<p>is by checking the upvar list</p>



<a name="201186027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201186027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201186027">(Jun 17 2020 at 19:00)</a>:</h4>
<p>I'm not sure how, I'm trying to avoid accesing upvars_mentioned</p>



<a name="201186111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201186111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201186111">(Jun 17 2020 at 19:01)</a>:</h4>
<p>btw I changed the topic for these messages</p>



<a name="201186114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201186114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201186114">(Jun 17 2020 at 19:01)</a>:</h4>
<p>Feels like it defeats the purpose of switiching over the closure_captures, also because once we start using Place we will have expr_id</p>



<a name="201186135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201186135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201186135">(Jun 17 2020 at 19:01)</a>:</h4>
<p>yah so you are saying</p>



<a name="201186149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201186149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201186149">(Jun 17 2020 at 19:01)</a>:</h4>
<p>I agree that the best strategy is probably to modify closure-captures <em>first</em></p>



<a name="201186190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201186190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201186190">(Jun 17 2020 at 19:02)</a>:</h4>
<p>to record also access information</p>



<a name="201186202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201186202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201186202">(Jun 17 2020 at 19:02)</a>:</h4>
<p>and then do the switch to use closure-captures</p>



<a name="201186209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201186209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201186209">(Jun 17 2020 at 19:02)</a>:</h4>
<p>is that what you are proposing?</p>



<a name="201186216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201186216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201186216">(Jun 17 2020 at 19:02)</a>:</h4>
<p>Yup</p>



<a name="201186265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201186265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201186265">(Jun 17 2020 at 19:02)</a>:</h4>
<p>I'll double check but looking through <code>TypeckTables</code> I didn't see anything in there for just this purpose, which surprised me a bit</p>



<a name="201186286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201186286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201186286">(Jun 17 2020 at 19:02)</a>:</h4>
<p>I thought we kept a bit of information on "why we chose to capture the variable in this way"</p>



<a name="201186296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201186296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201186296">(Jun 17 2020 at 19:02)</a>:</h4>
<p>but maybe not</p>



<a name="201186843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201186843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201186843">(Jun 17 2020 at 19:07)</a>:</h4>
<p>yeah I can't find it</p>



<a name="201186961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201186961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201186961">(Jun 17 2020 at 19:08)</a>:</h4>
<p>I'll update the issue with context and mark it blocked on closure_captures refactor</p>



<a name="201665079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201665079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201665079">(Jun 22 2020 at 21:47)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span>  We had discussed that closure captures look like </p>
<div class="codehilite"><pre><span></span><code><span class="k">struct</span> <span class="nc">ClosureCapture</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="sd">/// captured variable</span>
<span class="w">    </span><span class="n">hir_id</span>: <span class="nc">HirId</span><span class="p">,</span><span class="w"></span>

<span class="w">    </span><span class="n">upvar_id</span>: <span class="nc">UpvarId</span><span class="p">,</span><span class="w"> </span><span class="c1">// maybe this can go away</span>

<span class="w">    </span><span class="c1">//// some representative use we can cite for error messages</span>
<span class="w">    </span><span class="n">span</span>: <span class="nc">Span</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>as documented <a href="https://hackmd.io/BVFNLHnvSrG-d4MAshjmew">here</a></p>
<p>I think we can have </p>
<div class="codehilite"><pre><span></span><code><span class="c1">//  Place contains UpvarId for PlaceBase::Upvar</span>
<span class="c1">// This gives us access to Span from hir_id</span>
<span class="c1">// UpvarId contains the local var id that points to its declaration</span>
<span class="k">struct</span> <span class="nc">ClosureCaptureWithId</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">      </span><span class="n">captured_place</span>: <span class="nc">PlaceWIthHirId</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="c1">// this so that we don&#39;t have to generate the list of Place everytime we only need that.</span>
<span class="k">struct</span> <span class="nc">ClosureCapture</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">      </span><span class="n">captured_place</span>: <span class="nc">Place</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="201666663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201666663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201666663">(Jun 22 2020 at 22:03)</a>:</h4>
<p><span class="user-mention" data-user-id="281950">@Aman Arora</span> this sounds right, although it raises the question if the "closure capture" structs are even necessary.</p>



<a name="201667335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201667335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201667335">(Jun 22 2020 at 22:09)</a>:</h4>
<p>I was debating just a type alias, but decided to do it this way because <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/struct.Upvar.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/struct.Upvar.html</a>  , <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.LocalDefId.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.LocalDefId.html</a> and some other structs that I looked at, were essentially a single field. </p>
<p>My assumption was that this is to be future-proof, in case we decide to add more information. But as the current code stands type alias seems like a good option.</p>



<a name="201667832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189812-t-compiler/wg-rfc-2229/topic/upvar%20access%20spans/near/201667832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/189812-t-compiler/wg-rfc-2229/topic/upvar.20access.20spans.html#201667832">(Jun 22 2020 at 22:14)</a>:</h4>
<p>Actually scratch that, that's probably to provide member functions</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>